package com.example.demo.java8;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static java.lang.String.format;

/**
 * 〈一句话功能简述〉
 *
 * @author f_bao
 * @create 2018/5/15
 */
public class CompletableFutureDemo {


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("--------start");
        CompletableFuture.runAsync(() -> runableTest("亭子"));


        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> supplyAsyncTest("亭子"));
        System.out.println(future.get());

        CompletableFuture.runAsync(() -> runableTestEx("亭子")).exceptionally(ex -> {
            System.out.println(ex.getMessage());
            return null;
        });
    }

    public static void runableTest(String name){
        System.out.println("----------:" + name);
    }

    public static String runableTestEx(String name){
        System.out.println("----------EX:" + name);
        throw new RuntimeException("啊啊啊 啊啊 啊啊啊啊");
    }

    public static String supplyAsyncTest(String name) {
        System.out.println("enter --------- supplyAsyncTest");
        return "return test: " + name;
    }




}
